﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.ChaoBiaoGL
{
    public partial class ShuiBiaoHWH :BasePage
    {
        #region 属性

      

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 行业类型对象
        /// </summary>
        QS_CB_SBDYGXB _SB = new QS_CB_SBDYGXB();

        QS_CB_SBDYGXBBLL _SBBLL = new QS_CB_SBDYGXBBLL();

        QS_YG_YONGHUXXBLL _YHXXBLL = new QS_YG_YONGHUXXBLL();
        /// <summary>
        /// 存储过程调用类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
               // InitData();
                LoadData();
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }



        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            string msg = "";
            if (e.Parameter == "info")
            {
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                DataTable dt = _SBBLL.SelectQS_CB_SBDYGXBsDynamic(string.Format("i_jlzt=0 and id={0}", id), null);
                msg = string.Join("|", dt.Rows[0]["S_YHH"].ToString(), dt.Rows[0]["S_YHM"].ToString(),
                    dt.Rows[0]["S_SBH_ZLS"].ToString(), dt.Rows[0]["S_SBH_SZY"].ToString());
            }
            else if (e.Parameter == "Search")
            {
                string yhh = this.hdCollection.Get("yhh").ToString();
                DataTable dt = _YHXXBLL.SelectQS_YG_YONGHUXXesDynamic(string.Format("I_JLZT=0 AND S_YONGHUH='{0}'",yhh), null);
                msg = string.Join("|", dt.Rows[0]["S_YONGHUM"]);
            }
            else if (e.Parameter == "del")
            {
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                this._SB = _SBBLL.SelectQS_CB_SBDYGXB(id);
               
                //设置逻辑删除
                this._SB.I_JLZT = -1;
                //执行操作
                _SYS_LOGBLL.Log<QS_CB_SBDYGXB>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "表维护", OperateState.Delete, _SB, null);
                if (_SBBLL.InsertOrUpdate(_SB, null))
                {
                    msg = string.Join("|", "0");
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                if (id != 0)
                {
                    //修改操作
                    operateState = OperateState.Modify;
                    this._SB = this._SBBLL.SelectQS_CB_SBDYGXB(id);
                    this._SB.ID = id;
                }
                //添加
                else
                {
                    operateState = OperateState.Add;
                    this._SB.ID = 0;
                    this._SB.S_YHH = txtYHH.Text;
                    this._SB.S_YHM = txtYHM.Text;
                }
                this._SB.I_JLZT = 0;
                this._SB.S_SBH_ZLS = txtSBH_ZLS.Text;
                this._SB.S_SBH_SZY = txtSBH_SZY.Text;
                this._SB.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                this._SB.D_CAOZUORQ = BusinessTool.GetDataBaseDateTime();

                _SYS_LOGBLL.Log<QS_CB_SBDYGXB>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "表维护", operateState, _SB, null);
                bool result = this._SBBLL.InsertOrUpdate(_SB);
                //执行操作
                if (result)
                {
                    this.Status = GridViewStatus.Init;
                    msg = "0";
                }
            }
            e.Result = e.Parameter + "|0|" + msg;
        }

        #endregion

        #region 方法

      

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            this.dtSource = _SBBLL.SelectQS_CB_SBDYGXBsDynamic(string.Format("I_JLZT=0"), null);
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData();
        }

        #endregion        
    }
}